#include "ofile_c.h"

dword	ofile_c::release()
{
	delete this;
	return 0;
}

bool	ofile_c::open(kcstr _filename)
{
	m_file_impl.open(_filename, "wb");
	return is_open();
}

bool ofile_c::open(kcwstr _file_name)
{
	m_file_impl.open(_file_name, L"wb");
	return is_open();
}


void	ofile_c::close()
{
	m_file_impl.close();
}

bool	ofile_c::is_open() const
{
	return m_file_impl.is_open();
}

bool	ofile_c::seek(dword _offset, seek_dir _dir)
{
	return m_file_impl.seek(_offset, _dir);
}

dword	ofile_c::tell() const
{
	return m_file_impl.tell();
}

dword	ofile_c::length() const
{
	return m_file_impl.length();
}

dword	ofile_c::write(const void* _mem, dword _size)
{
	return m_file_impl.write(_mem, _size);
}

kcstr	ofile_c::name() const
{
	return m_file_impl.name();
}

io::ofile*	io::write_file(kcstr _filename)
{
	ofile* f = create_ofile();
	if(f->open(_filename))
	{
		return f;
	}
	else
	{
		cmn::safe_release(f);
		return nullptr;
	}
}

io::ofile*	io::write_file(kcwstr _filename)
{
	ofile* f = create_ofile();
	if (f->open(_filename))
	{
		return f;
	}
	else
	{
		cmn::safe_release(f);
		return nullptr;
	}
}

io::ofile*	io::create_ofile()
{
	return new ofile_c();
}
